<?php
/**
 * alltosun.com  ts_helper.php
 * ============================================================================
 * 版权所有 (C) 2009-2013 北京互动阳光科技有限公司，并保留所有权利。
 * 网站地址: http://www.alltosun.com
 * ----------------------------------------------------------------------------
 * 许可声明：这是一个开源程序，未经许可不得将本软件的整体或任何部分用于商业用途及再发布。
 * ============================================================================
 * $Author: 王德康 (wangdk@alltosun.com) $
 * $Date: 2016-3-30 下午3:41:57 $
 * $Id$
 */

class ts_helper
{
    private static $table = 'ts';
    private static $model = '';
    private static $ns_table_array = array();

    public static function begin()
    {
        self::$model = _model(self::$table);
        self::$model->beginTransaction();
    }

    public static function _model($table)
    {
        self::$model->add_time = 0;
        self::$model->setTable($table);
        self::$ns_table_array[] = $table;
        return self::$model;
    }

    public static function commit()
    {
       if (self::$ns_table_array) {
           foreach(self::$ns_table_array as $table_name) {
               _model($table_name)->mc_delete_ns();
           }
       }
       return self::$model->commit();
    }

    public static function rollback()
    {
        return self::$model->rollBack();
    }

    public static function trace_log($e, $is_print = 0)
    {
        $trace_str = $e->DebugMsg ."\n". $e->getTraceAsString();
        error_log($trace_str);
        if ($is_print && !ONDEV) echo $trace_str;
    }
}